package com.tour.modules.web.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tour.common.utils.PageUtils;
import com.tour.common.utils.Query;
import com.tour.common.utils.R;
import com.tour.modules.web.entity.TCategoryEntity;
import com.tour.modules.web.service.TCategoryService;

/**
 * 景点类别表
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-01-06 22:44:15
 */
@RestController
@RequestMapping("tcategory")
public class TCategoryController {
	@Autowired
	private TCategoryService tCategoryService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params) {
		// 查询列表数据
		Query query = new Query(params);

		List<TCategoryEntity> tCategoryList = tCategoryService.queryList(query);
		int total = tCategoryService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(tCategoryList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Long id) {
		TCategoryEntity tCategory = tCategoryService.queryObject(id);

		return R.ok().put("tCategory", tCategory);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody TCategoryEntity tCategory) {
		tCategoryService.save(tCategory);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody TCategoryEntity tCategory) {
		tCategoryService.update(tCategory);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Long[] ids) {
		tCategoryService.deleteBatch(ids);

		return R.ok();
	}

	/**
	 * 查询所有类别
	 */
	@RequestMapping("/listInfoAll")
	public R listInfoAll() {
		List<TCategoryEntity> categoryEntity = tCategoryService.queryListInfoAll();
		return R.ok().put("categoryEntity", categoryEntity);
	}
}
